﻿using System;
using System.Reflection.Emit;
using Sigil.Impl;

namespace Sigil
{
	public partial class Emit<DelegateType>
	{
		/// <summary>
		/// Converts a TypedReference on the stack into a RuntimeTypeHandle for the type contained with it.
		///
		/// __makeref(Int32) on the stack would become the RuntimeTypeHandle for typeof(Int32), for example.
		/// </summary>
		public Emit<DelegateType> ReferenceAnyType()
		{
			var transitions =
					new[] {
                    new StackTransition(new[] { typeof(TypedReference) }, new [] { typeof(RuntimeTypeHandle) })
                };

			UpdateState(OpCodes.Refanytype, Wrap(transitions, "ReferenceAnyType"));

			return this;
		}
	}
}